import { ref, computed, reactive } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', () => {
  const regionMap = reactive(new Map()); /*行政区域map*/

  function setRegionMap(data) {
    let deepLoop = (targetAry = data, parentCode) => {
      targetAry.forEach(item => {
        item.parentCode = parentCode;
        item.parent = regionMap.get(parentCode);
        regionMap.set(item.code, item);
        if (item.children.length > 0) deepLoop(item.children, item.code);
      });
    };
    deepLoop();
    deepLoop = null;/*销毁*/
  }

  return { regionMap, setRegionMap }
})
